package com.aitao.beans;

import java.io.File;
import java.util.Set;

public class Fileset {
    /**
     * 文件目录
     */
    private File basedir;

    /**
     * 文件
     */
    private File file;

    /**
     * 包含子文件/目录
     */
    private Set<String> includes;

    /**
     * 排除子文件/目录
     */
    private Set<String> excludes;

    /**
     * 是否仅删除符号链接
     */
    private boolean followSymlinks;

    /**
     * 操作文件时，出现错误是否异常中止
     */
    private boolean failOnError;

    /**
     * 操作文件时，出现错误是否重试
     */
    private boolean retryOnError;

    /**
     * 重试次数，设置retryOnError=true时有效
     */
    private int retryCount;

    /**
     * 延迟时间，设置retryOnError=true时有效
     */
    private long retryDelay;

    /**
     * 文件过滤器，过滤basedir目录下的文件/目录，默认不过滤任何文件
     */
    private String filter;

    /**
     * 文件过滤时，是否过滤掉空目录
     */
    private boolean includeEmptyDir;

    public Fileset() {
        this.followSymlinks = false;
        this.failOnError = true;
        this.retryOnError = false;
        this.retryDelay = 100;
        this.retryCount = 3;
        this.filter = "*";
        this.includeEmptyDir = false;
    }

    public Fileset(File file, boolean followSymlinks, boolean failOnError, boolean retryOnError) {
        this();
        this.basedir = file;
        this.followSymlinks = followSymlinks;
        this.failOnError = failOnError;
        this.retryOnError = retryOnError;
    }

    public static Fileset create() {
        return new Fileset();
    }

    public File getBasedir() {
        return basedir;
    }

    public Fileset setBasedir(File basedir) {
        //只能设置目录文件
        this.basedir = basedir;
        return this;
    }

    public File getFile() {
        return file;
    }

    public Fileset setFile(File file) {
        //只能设置文件
        this.file = file;
        return this;
    }

    public Set<String> getIncludes() {
        return includes;
    }

    public Fileset setIncludes(Set<String> includes) {
        this.includes = includes;
        return this;
    }

    public Set<String> getExcludes() {
        return excludes;
    }

    public Fileset setExcludes(Set<String> excludes) {
        this.excludes = excludes;
        return this;
    }

    public boolean isFollowSymlinks() {
        return followSymlinks;
    }

    public Fileset setFollowSymlinks(boolean followSymlinks) {
        this.followSymlinks = followSymlinks;
        return this;
    }

    public boolean isFailOnError() {
        return failOnError;
    }

    public Fileset setFailOnError(boolean failOnError) {
        this.failOnError = failOnError;
        return this;
    }

    public boolean isRetryOnError() {
        return retryOnError;
    }

    public Fileset setRetryOnError(boolean retryOnError) {
        this.retryOnError = retryOnError;
        return this;
    }

    public int getRetryCount() {
        return retryCount;
    }

    public void setRetryCount(int retryCount) {
        this.retryCount = retryCount;
    }

    public long getRetryDelay() {
        return retryDelay;
    }

    public void setRetryDelay(long retryDelay) {
        this.retryDelay = retryDelay;
    }


    public String getFilter() {
        return filter;
    }

    public Fileset setFilter(String filter) {
        this.filter = filter;
        return this;
    }

    public boolean isIncludeEmptyDir() {
        return includeEmptyDir;
    }

    public void setIncludeEmptyDir(boolean includeEmptyDir) {
        this.includeEmptyDir = includeEmptyDir;
    }
}
